#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 105;
int n,a[maxn],b[maxn],f[maxn];

int solve(){
	int x,k;
	cin>>x>>k;
	for(int i=1;i<=x;i++)	cin>>a[i];
	for(int i=1;i<=x;i++)	cin>>b[i];
	for(int i=1;i<=x;i++)	f[i] = b[i];
	for(int i=2;i<=x;i++){
		for(int j=1;j<x;j++){
			if((a[i]-a[j]>k) && f[j]+b[i]>f[i]){
				f[i] = f[j]+b[i];
			}
		}
	}
	int max = 0;
	for(int i=1;i<=x;i++){
		if(f[i]>max)max = f[i];
	}
	return max;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		memset(a,0,sizeof a);
		memset(b,0,sizeof b);
		memset(f,0,sizeof f);
		cout<<solve()<<endl;
	}
	return 0;
}